/*
 * @description: 
 * @Author: Islands
 * @Date: 2024-06-15 02:04:08
 * @LastEditTime: 2024-06-20 13:58:33
 */
import { ILoginData } from "@/api/types/login.d";
import { useStore } from '@/plugins/pinia/index';
import { AES_Encrypt } from '@/utils/aes-crypto/index';
import { LoginWay } from '@/enums/index';
import router from '@/plugins/router/index'
import { ElMessage } from 'element-plus';

import { doLogin, doToken } from '@/api/service/login';


//登录表单
class LoginData {
    username: string;
    password?: string;
    grantType: string;
    code?: string;
    clientId?: string;
    clientSecret?: string;
    scope?: string;
    constructor(username: string, grantType: string, password?: string, code?: string, clientId?: string, clientSecret?: string, scope?: string) {
        this.username = username;
        this.password = AES_Encrypt(password);
        this.grantType = grantType;
        this.code = code;
        this.clientId = clientId;
        this.clientSecret = AES_Encrypt(clientSecret);
        this.scope = scope;
    }
}

/**
 * 密码模式登录
 * @param formEl
 * @param loginForm
 */
export const pwdLogin = async (loginForm: ILoginData) => {
    //执行登录方法
    let result: any = await useStore().loginIn(new LoginData(loginForm.username, LoginWay.Pwd, loginForm.password, '', 'yang', 'yang_secret', 'openid'));
    if (null != result) {
        router.push('/home')
    }
};
